12#ifndef ROC_CORE_SLICE_H_
13#define ROC_CORE_SLICE_H_
36 data_ = buffer->
data();
37 size_ = buffer->
size();
47 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)from,
50 if (to > buffer.
size()) {
51 roc_panic(
"slice: out of bounds: available=[%lu,%lu), requested=[%lu,%lu)",
52 (
unsigned long)0, (
unsigned long)buffer.
size(), (
unsigned long)from,
56 data_ = buffer.
data() + from;
78 return buffer_->size() - size_t(data_ - buffer_->data());
86 roc_panic(
"slice: out of bounds: available=%lu, requested=%lu",
87 (
unsigned long)cap, (
unsigned long)new_size);
95 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)from,
99 roc_panic(
"slice: out of bounds: available=[%lu,%lu), requested=[%lu,%lu)",
100 (
unsigned long)0, (
unsigned long)size_, (
unsigned long)from,
104 ret.buffer_ = buffer_;
105 ret.data_ = data_ + from;
106 ret.size_ = to - from;
122 operator const struct unspecified_bool*()
const {
123 return (
const unspecified_bool*)data_;
T * data()
Get buffer data.
size_t size() const
Get maximum number of elements.
Shared ownership intrusive pointer.
void resize(size_t new_size)
Change slice size, up to the available capacity.
size_t capacity() const
Get maximum possible number of elements in slice.
Slice range(size_t from, size_t to) const
Construct a slice pointing to a part of this slice.
void print() const
Print slice to stderr.
T * data() const
Get slice data.
Slice()
Construct empty slice.
size_t size() const
Get number of elements in slice.
Slice(Buffer< T > *buffer)
Construct slice pointing to a buffer.
Slice(Buffer< T > &buffer, size_t from, size_t to)
Construct slice pointing to a part of a buffer.
void print_buffer_slice(const uint8_t *inner, size_t inner_size, const uint8_t *outer, size_t outer_size)
Print a slice of bytes buffer.
#define roc_panic(...)
Print error message and terminate program gracefully.
Shared ownership intrusive pointer.